<?php
require_once 'database.php';
require_once '../DTO/KHACHHANG_DTO.php';
class xl_khach_hang extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from khach_hang limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from khach_hang";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from khach_hang where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function kt_email($email)
	{
		$sql = "select * from khach_hang where email = '$email'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from khach_hang where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}

    function them_giaodien(KHACHHANG_DTO $info)
    {
        $info->ho_ten = stripslashes($info->ho_ten);
        $info->ho_ten = addslashes($info->ho_ten);


        $info->dien_thoai = stripslashes($info->dien_thoai);
        $info->dien_thoai = addslashes($info->dien_thoai);

        $info->email = stripslashes($info->email);
        $info->email = addslashes($info->email);

        $info->chuc_vu = stripslashes($info->chuc_vu);
        $info->chuc_vu = addslashes($info->chuc_vu);


        $sql = "INSERT INTO khach_hang(ho_ten,dien_thoai,email,chuc_vu ) VALUES   (
                                                    '$info->ho_ten',
                                                    '$info->dien_thoai',
                                                    '$info->email',
                                                    '$info->chuc_vu'
		                                        )";
        $this->setQuery($sql);
        return $this->query();
    }

	function them(KHACHHANG_DTO $info)
	{
        $info->ho_ten = stripslashes($info->ho_ten);
        $info->ho_ten = addslashes($info->ho_ten);

        $info->dia_chi = stripslashes($info->dia_chi);
        $info->dia_chi = addslashes($info->dia_chi);

        $info->dien_thoai = stripslashes($info->dien_thoai);
        $info->dien_thoai = addslashes($info->dien_thoai);

        $info->email = stripslashes($info->email);
        $info->email = addslashes($info->email);

        $info->chuc_vu = stripslashes($info->chuc_vu);
        $info->chuc_vu = addslashes($info->chuc_vu);

        $info->thong_tin_them = stripslashes($info->thong_tin_them);
        $info->thong_tin_them = addslashes($info->thong_tin_them);


		$sql = "INSERT INTO khach_hang VALUES   (
                                                    '$info->ho_ten',
                                                    '$info->ngay_sinh',
                                                    '$info->dia_chi',
                                                    '$info->dien_thoai',
                                                    '$info->email',
                                                    '$info->chuc_vu',
                                                    '$info->thong_tin_them',
                                                    '$info->trang_thai',
                                                    '$info->ma_phieu_dk'
		                                        )";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $ho_ten, $ngay_sinh, $gioi_tinh, $dia_chi, $dien_thoai, $email, $vi_tri_ung_tuyen, $tu_gioi_thieu, $trang_thai)
	{
		$ma = intval($ma);
		$ho_ten = stripslashes($ho_ten);
		$ho_ten = addslashes($ho_ten);
		$dia_chi = stripslashes($dia_chi);
		$dia_chi = addslashes($dia_chi);
		$dien_thoai = stripslashes($dien_thoai);
		$dien_thoai = addslashes($dien_thoai);
		$email = stripslashes($email);
		$email = addslashes($email);
		$vi_tri_ung_tuyen = stripslashes($vi_tri_ung_tuyen);
		$vi_tri_ung_tuyen = addslashes($vi_tri_ung_tuyen);
		$tu_gioi_thieu = stripslashes($tu_gioi_thieu);
		$tu_gioi_thieu = addslashes($tu_gioi_thieu);

		$sql ="UPDATE khach_hang SET ho_ten= '$ho_ten', ngay_sinh= '$ngay_sinh', gioi_tinh= '$gioi_tinh', dia_chi= '$dia_chi', dien_thoai= '$dien_thoai', email= '$email', vi_tri_ung_tuyen= '$vi_tri_ung_tuyen', tu_gioi_thieu= '$tu_gioi_thieu', trang_thai= '$trang_thai' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		//$sql = "select * from khach_hang where	$ho_ten like %tu_khoa% or 	$dia_chi like %tu_khoa% or 	$dien_thoai like %tu_khoa% or 	$email like %tu_khoa% or 	$vi_tri_ung_tuyen like %tu_khoa% or 	$tu_gioi_thieu like %tu_khoa%";
		//$this->setQuery($sql);
		return $this->loadAllRow();
	}
 }
?>